<?php
$GLOBALS['Md'] = "TimeClock";
$GLOBALS['Pd'] = "B";
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
print heade(); 
module($BSD['DB00']);
	    $CVacs = "SELECT 
						main_offices.name AS office,
						main_offices.ref
				FROM timeclock_vacs
		INNER JOIN timeclock_profiles ON timeclock_profiles.main_users_ref = timeclock_vacs.RefUser
		INNER JOIN main_users ON main_users.ref = timeclock_profiles.main_users_ref
		INNER JOIN main_offices ON main_users.ref_office = main_offices.ref
		WHERE timeclock_vacs.Type = 1
		AND timeclock_vacs.Status < 2
		GROUP BY main_offices.ref";
		$Vacs = $GLOBALS['CONN']->db_array($CVacs);
		
		echo '<table width="100%"  border="1" cellspacing="0" cellpadding="1">';
		
		for ($f = 1; $f <= $Vacs[0]; $f++) { ?>

  <tr>
    <td colspan="4"><strong>Loja <?php echo $Vacs[$f]['office'];?></strong></td>
  </tr>
  <?php 
  	    $CVacss = "SELECT 
		   				
						timeclock_vacs.ref AS vcref,
						DATE(timeclock_vacs.TimeStart) AS TimeStart,
						DATE(timeclock_vacs.TimeEnd) AS TimeEnd,
						timeclock_vacs.Days,
						timeclock_vacs.Status,
						timeclock_vacs.Observations,
						main_offices.name AS office, main_users.name AS name,
						 timeclock_profiles.ref,
						 timeclock_profiles.main_users_ref,
						 timeclock_profiles.delay,
						 timeclock_profiles.mon1,
						 timeclock_profiles.mon2,
						 timeclock_profiles.mon3,
						 timeclock_profiles.mon4,
						 timeclock_profiles.mon5,
						 timeclock_profiles.mon6,
						 timeclock_profiles.mon0,
						 timeclock_profiles.ProfileType
				FROM timeclock_vacs
		INNER JOIN timeclock_profiles ON timeclock_profiles.main_users_ref = timeclock_vacs.RefUser
		INNER JOIN main_users ON main_users.ref = timeclock_profiles.main_users_ref
		INNER JOIN main_offices ON main_users.ref_office = main_offices.ref
		WHERE timeclock_vacs.Type = 1
		AND timeclock_vacs.Status < 2
		AND main_offices.ref = {$Vacs[$f]['ref']}";
		$Vacss = $GLOBALS['CONN']->db_array($CVacss);
		for ($r = 1; $r <= $Vacss[0]; $r++) { ?>
  <tr>
    <td width="20%"><?php echo $Vacss[$r]['name'];?></td>
    <td width="15%"><?php echo $Vacss[$r]['TimeStart'];?></td>
    <td width="15%"><?php echo $Vacss[$r]['TimeEnd'];?></td>
    <td width="70%"><?php echo $Vacss[$r]['Observations'];?></td>
  </tr>
<?php } }
	echo '</table>'; ?>
